package com.ruoyi.project.dict.cizuaccess.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.cizuaccess.domain.CizuAccess;
import com.ruoyi.project.dict.cizuaccess.service.ICizuAccessService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 词组访问频率Controller
 * 
 * @author shixiangwen
 * @date 2020-07-07
 */
@Controller
@RequestMapping("/dict/cizuaccess")
public class CizuAccessController extends BaseController
{
    private String prefix = "dict/cizuaccess";

    @Autowired
    private ICizuAccessService cizuAccessService;

    @RequiresPermissions("dict:cizuaccess:view")
    @GetMapping()
    public String cizuaccess()
    {
        return prefix + "/cizuaccess";
    }

    /**
     * 查询词组访问频率列表
     */
    @RequiresPermissions("dict:cizuaccess:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CizuAccess cizuAccess)
    {
        startPage();
        List<CizuAccess> list = cizuAccessService.selectCizuAccessList(cizuAccess);
        return getDataTable(list);
    }

    /**
     * 导出词组访问频率列表
     */
    @RequiresPermissions("dict:cizuaccess:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CizuAccess cizuAccess)
    {
        List<CizuAccess> list = cizuAccessService.selectCizuAccessList(cizuAccess);
        ExcelUtil<CizuAccess> util = new ExcelUtil<CizuAccess>(CizuAccess.class);
        return util.exportExcel(list, "cizuaccess");
    }

    /**
     * 新增词组访问频率
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存词组访问频率
     */
    @RequiresPermissions("dict:cizuaccess:add")
    @Log(title = "词组访问频率", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CizuAccess cizuAccess)
    {
        return toAjax(cizuAccessService.insertCizuAccess(cizuAccess));
    }

    @RequiresPermissions("dict:cizuaccess:add")
    @Log(title = "词组访问频率", businessType = BusinessType.INSERT)
    @PostMapping("/importToCizu")
    @ResponseBody
    public AjaxResult importToCizu(Long id, String ci)
    {
        return toAjax(cizuAccessService.importToCizu(id, ci));
    }


    /**
     * 修改词组访问频率
     */
    @GetMapping("/edit/{ci}")
    public String edit(@PathVariable("ci") String ci, ModelMap mmap)
    {
        CizuAccess cizuAccess = cizuAccessService.selectCizuAccessById(ci);
        mmap.put("cizuAccess", cizuAccess);
        return prefix + "/edit";
    }

    /**
     * 修改保存词组访问频率
     */
    @RequiresPermissions("dict:cizuaccess:edit")
    @Log(title = "词组访问频率", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CizuAccess cizuAccess)
    {
        return toAjax(cizuAccessService.updateCizuAccess(cizuAccess));
    }

    /**
     * 删除词组访问频率
     */
    @RequiresPermissions("dict:cizuaccess:remove")
    @Log(title = "词组访问频率", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cizuAccessService.deleteCizuAccessByIds(ids));
    }
}
